package com.kd.juhaowan.ui.holder;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.flyjingfish.shapeimageviewlib.ShapeImageView;
import com.kd.juhaowan.R;
import com.kd.juhaowan.http.model.SubCommentModel;
import com.kd.juhaowan.ui.adapter.BaseViewHolder;
import com.kd.juhaowan.utils.GlideHelper;
import com.kd.juhaowan.utils.LogUtil;


import butterknife.BindView;

public class CommentSubViewHolderTwoPic extends BaseViewHolder {
    @BindView(R.id.subcomment_child)
    TextView nameView;

    @BindView(R.id.item_image)
    ShapeImageView imageView;
    @BindView(R.id.item_image2)
    ShapeImageView imageView2;

    public CommentSubViewHolderTwoPic(@NonNull View itemView) {
        super(itemView);
    }


    private SpannableString getSpanString(SubCommentModel model){
        String temp = model.getUser_text().getNickname();
//         if(model.getIs_author()==1){
//             temp+=" 楼主 ";
//         }
        if(model.getUser_reply_text()!=null&&!TextUtils.isEmpty(model.getUser_reply_text().getNickname())){
            temp+="回复@"+model.getUser_reply_text().getNickname()+" ";
        }
        temp+="："+model.getContent();
        SpannableString spannableString = new SpannableString(temp);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#603FE0")), temp.indexOf(model.getUser_text().getNickname()), temp.indexOf(model.getUser_text().getNickname())+model.getUser_text().getNickname().length(), 0);
//        if(model.getIs_author()==1){
//            temp+=" 楼主 ";
//            spannableString.setSpan(new AbsoluteSizeSpan(10,true), temp.indexOf("楼主"), temp.indexOf("楼主")+2, 0);
//            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#898A8F")), temp.indexOf("楼主"), temp.indexOf("楼主")+2, 0);
//        }

        if(model.getUser_reply_text()!=null&&!TextUtils.isEmpty(model.getUser_reply_text().getNickname())){
            LogUtil.debugLog("name"+model.getUser_reply_text().getNickname());
            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#603FE0")), temp.indexOf("回复")+2, temp.lastIndexOf(model.getUser_reply_text().getNickname())+model.getUser_reply_text().getNickname().length(), 0);
        }
        LogUtil.debugLog(model.toString()+"\n"+spannableString);
        return spannableString;
    }
    @SuppressLint("ResourceType")
    public void setDate(SubCommentModel model){
        nameView.setText(getSpanString(model));
        GlideHelper.loadGoodsCover(Glide.with(getItemView()),imageView,model.getImages()[0]);
        GlideHelper.loadGoodsCover(Glide.with(getItemView()),imageView2,model.getImages()[1]);

    }


}
